package com.headwind.logistics.system.controller;

import com.headwind.logistics.common.pojo.GoodsIssueType;
import com.headwind.logistics.common.pojo.GoodsType;
import com.headwind.logistics.common.util.LayuiUtil;
import com.headwind.logistics.common.util.RestResult;
import com.headwind.logistics.common.util.ResultGenerator;
import com.headwind.logistics.system.service.intl.GoodsIssueTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author你爸爸 Date2020/7/22 15:54
 * Version 1.0
 * DESCRIPTION
 */
@Controller
@Transactional
public class GoodsIssueTypeController {
    @Resource
    private ResultGenerator resultGenerator;

    @Autowired
    private GoodsIssueTypeService goodsIssueTypeService;

    //查询
    @GetMapping("/admin/system/selectGoodsIssueType")
    @ResponseBody
    public LayuiUtil selectGoodsIssueType(Integer page, Integer limit,String goodsName){
        List<GoodsIssueType> list=goodsIssueTypeService.selectGoodsIssueType(page,limit,goodsName);
        return LayuiUtil.data(goodsIssueTypeService.selectGoodsIssueType(null,null,null).size(),list);
    }

    //新增
    @RequestMapping("/admin/system/insertGoodsIssueType")
    @ResponseBody
    protected RestResult insertGoodsIssueType(String goodsIssueTypeName,String goodsIssueTypeNo){
        GoodsIssueType goodsIssueType=new GoodsIssueType();
        goodsIssueType.setGoodsIssueTypeName(goodsIssueTypeName);
        goodsIssueType.setGoodsIssueTypeNo(goodsIssueTypeNo);
        int count=goodsIssueTypeService.insertGoodsIssueType(goodsIssueType);
        if (count>0){
            return  resultGenerator.getSuccessResult("新增成功",count);
        }
        return resultGenerator.getFailResult("新增失败，重新试试？",count);
    }

    //删除
    @RequestMapping("/admin/system/deleteGoodsIssueType")
    @ResponseBody
    public RestResult deleteGoodsIssueType(Long goodsIssueTypeId){
      int count=goodsIssueTypeService.deleteGoodsIssueType(goodsIssueTypeId);
      if (count>0){
          return  resultGenerator.getSuccessResult("删除成功",count);
      }
        return resultGenerator.getFailResult("删除失败，重新试试？",count);
      }

     //修改
     @RequestMapping("/admin/system/updateGoodsIssueType")
     @ResponseBody
     public RestResult updateGoodsIssueType(Long goodsIssueTypeId,String goodsIssueTypeName,String goodsIssueTypeNo){
         GoodsIssueType goodsIssueType=new GoodsIssueType();
         goodsIssueType.setGoodsIssueTypeId(goodsIssueTypeId);
         goodsIssueType.setGoodsIssueTypeName(goodsIssueTypeName);
         goodsIssueType.setGoodsIssueTypeNo(goodsIssueTypeNo);
         int count=goodsIssueTypeService.updateGoodsIssueType(goodsIssueType);
         if (count>0){
             return resultGenerator.getSuccessResult("修改成功",count);
         }
         return resultGenerator.getFailResult("修改失败，重新试试？",count);
     }
}
